package com.klun.project.common.constans.leetcode;

import com.klun.project.common.constans.entity.TreeNode;

/**
 * 感觉也不是特别适合描述
 */
public class Solution687 {
	int res;

	public int longestUnivaluePath(TreeNode root) {
		res = 0;
		dfs(root);
		return res;
	}

	public int dfs(TreeNode root) {
		if (root == null) {
			return 0;
		}
		int left = dfs(root.left), right = dfs(root.right);
		int left1 = 0, right1 = 0;
		if (root.left != null && root.left.val == root.val) {
			left1 = left + 1;
		}
		if (root.right != null && root.right.val == root.val) {
			right1 = right + 1;
		}
		return Math.max(left1, right1);
	}

}
